<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<title>Parse Clauses</title>
<link href="../docs-assets/Breadcrumbs.css" rel="stylesheet" rev="stylesheet" type="text/css">
		<meta name="viewport" content="width=device-width initial-scale=1">
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<meta http-equiv="Content-Language" content="en-gb">

<link href="../docs-assets/Contents.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Progress.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Navigation.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Fonts.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Base.css" rel="stylesheet" rev="stylesheet" type="text/css">
<script>
function togglePopup(material_id) {
  var popup = document.getElementById(material_id);
  popup.classList.toggle("show");
}
</script>

<link href="../docs-assets/Popups.css" rel="stylesheet" rev="stylesheet" type="text/css">
<script src="http://code.jquery.com/jquery-1.12.4.min.js"
	integrity="sha256-ZosEbRLbNQzLpnKIkEdrPv7lOy9C27hHQ+Xp8a4MxAQ=" crossorigin="anonymous"></script>

<script src="../docs-assets/Bigfoot.js"></script>
<link href="../docs-assets/Bigfoot.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Colours.css" rel="stylesheet" rev="stylesheet" type="text/css">
		
	</head>
	<body class="commentary-font">
		<nav role="navigation">
		<h1><a href="../index.html"><img src="../docs-assets/Inform.png" height=72> </a></h1>
<ul><li><a href="../index.html">home</a></li>
</ul><h2>Compiler</h2><ul>
<li><a href="../structure.html">structure</a></li>
<li><a href="../inbuildn.html">inbuild</a></li>
<li><a href="../inform7n.html">inform7</a></li>
<li><a href="../intern.html">inter</a></li>
<li><a href="../services.html">services</a></li>
<li><a href="../secrets.html">secrets</a></li>
</ul><h2>Other Tools</h2><ul>
<li><a href="../inblorbn.html">inblorb</a></li>
<li><a href="../inform6.html">inform6</a></li>
<li><a href="../inpolicyn.html">inpolicy</a></li>
</ul><h2>Resources</h2><ul>
<li><a href="../extensions.html">extensions</a></li>
<li><a href="../kits.html">kits</a></li>
</ul><h2>Repository</h2><ul>
<li><a href="https://github.com/ganelson/inform"><img src="../docs-assets/github.png" height=0> github</a></li>
</ul><h2>Related Projects</h2><ul>
<li><a href="https://github.com/ganelson/inweb"><img src="../docs-assets/github.png" height=0> inweb</a></li>
<li><a href="https://github.com/ganelson/intest"><img src="../docs-assets/github.png" height=0> intest</a></li>
</ul>
		</nav>
		<main role="main">
		<!-- Weave of 'Parse Clauses' generated by inweb -->
<div class="breadcrumbs">
    <ul class="crumbs"><li><a href="../index.html">Home</a></li><li><a href="../inform7n.html">Inform7</a></li><li><a href="index.html">if</a></li><li><a href="index.html#4">Chapter 4: Actions</a></li><li><b>Parse Clauses</b></li></ul></div>
<p class="purpose">Parsing the clauses part of an AP from source text.</p>

<ul class="toc"><li><a href="4-pc.html#SP3">&#167;3. Internal test</a></li></ul><hr class="tocbar">

<p class="commentary firstcommentary"><a id="SP1" class="paragraph-anchor"></a><b>&#167;1. </b>For nearly two decades the function below (and its allied code in
<a href="4-anl.html" class="internal">Action Name Lists</a>) was the most troublesome, and hardest to understand,
code in the whole compiler, a simply awful place reminding me somehow of
Douglas Adams's Frogstar.<sup id="fnref:1"><a href="#fn:1" rel="footnote">1</a></sup> The AP parser was almost as cranky as the
type-checker, but that at least had the excuse of performing a complicated
function. Periodic improvements clarified only that the action pattern parser
was difficult to predict, and still did odd things in edge cases.
</p>

<p class="commentary">A therapeutic rewrite was finally made in March 2021; the algorithm works
entirely differently but appears to match a superset of cases that the old one
did, and is much easier to specify.
</p>

<ul class="footnotetexts"><li class="footnote" id="fn:1"><p class="inwebfootnote"><sup id="fnref:1"><a href="#fn:1" rel="footnote">1</a></sup> Information about package holidays on the Frogstar can be found in the leaflet
"Sun, Sand, and Suffering on the Most Totally Evil Place in the Galaxy".
<a href="#fnref:1" title="return to text"> &#x21A9;</a></p></li></ul>
<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">action_pattern</span><span class="plain-syntax"> *</span><span class="function-syntax">ParseClauses::ap_seven</span><button class="popup" onclick="togglePopup('usagePopup1')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup1">Usage of <span class="code-font"><span class="function-syntax">ParseClauses::ap_seven</span></span>:<br/><a href="4-pc.html#SP4">&#167;4</a><br/>Parse Action Patterns - <a href="4-pap.html#SP16">&#167;16</a></span></button><span class="plain-syntax">(</span><span class="identifier-syntax">wording</span><span class="plain-syntax"> </span><span class="identifier-syntax">W</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">LOGIF</span><span class="plain-syntax">(</span><span class="identifier-syntax">ACTION_PATTERN_PARSING</span><span class="plain-syntax">, </span><span class="string-syntax">"Level Seven on: %W\n"</span><span class="plain-syntax">, </span><span class="identifier-syntax">W</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">action_name_list</span><span class="plain-syntax"> *</span><span class="identifier-syntax">list</span><span class="plain-syntax"> =</span>
<span class="plain-syntax">        </span><a href="4-anl.html#SP29" class="function-link"><span class="function-syntax">ActionNameLists::parse</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">W</span><span class="plain-syntax">, </span><a href="4-pap.html#SP4" class="function-link"><span class="function-syntax">ParseActionPatterns::current_tense</span></a><span class="plain-syntax">(), </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">LOGIF</span><span class="plain-syntax">(</span><span class="identifier-syntax">ACTION_PATTERN_PARSING</span><span class="plain-syntax">, </span><span class="string-syntax">"Action name list for %W is:\n$L"</span><span class="plain-syntax">, </span><span class="identifier-syntax">W</span><span class="plain-syntax">, </span><span class="identifier-syntax">list</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><a href="4-anl.html#SP10" class="function-link"><span class="function-syntax">ActionNameLists::length</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">list</span><span class="plain-syntax">) == </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>

<span class="plain-syntax">    </span><span class="named-paragraph-container code-font"><a href="4-pc.html#SP1_1" class="named-paragraph-link"><span class="named-paragraph">Reduce the list to the first viable entry at each word position</span><span class="named-paragraph-number">1.1</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">LOGIF</span><span class="plain-syntax">(</span><span class="identifier-syntax">ACTION_PATTERN_PARSING</span><span class="plain-syntax">, </span><span class="string-syntax">"Reduced to viability:\n$L"</span><span class="plain-syntax">, </span><span class="identifier-syntax">list</span><span class="plain-syntax">);</span>

<span class="plain-syntax">    </span><span class="named-paragraph-container code-font"><a href="4-pc.html#SP1_2" class="named-paragraph-link"><span class="named-paragraph">Reject the resulting list if two or more entries contain clauses</span><span class="named-paragraph-number">1.2</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="named-paragraph-container code-font"><a href="4-pc.html#SP1_3" class="named-paragraph-link"><span class="named-paragraph">Reject the resulting list if, given the clauses, two actions are immiscible</span><span class="named-paragraph-number">1.3</span></a></span><span class="plain-syntax">;</span>

<span class="plain-syntax">    </span><span class="named-paragraph-container code-font"><a href="4-pc.html#SP1_4" class="named-paragraph-link"><span class="named-paragraph">Produce and return an action pattern from what survives of the list</span><span class="named-paragraph-number">1.4</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP1_1" class="paragraph-anchor"></a><b>&#167;1.1. </b>A typical action list might look like the following, which came from the text
"looking or taking inventory in the presence of Hans in the Laboratory". There
are six different options at word position 2 (i.e., the "taking" part) but only
one at position 0 ("looking").
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">(1). +2 </span><span class="identifier-syntax">taking</span><span class="plain-syntax"> </span><span class="identifier-syntax">inventory</span><span class="plain-syntax"> [</span><span class="identifier-syntax">in:</span><span class="plain-syntax"> </span><span class="identifier-syntax">the</span><span class="plain-syntax"> </span><span class="identifier-syntax">laboratory</span><span class="plain-syntax">] [</span><span class="identifier-syntax">in</span><span class="plain-syntax">-</span><span class="identifier-syntax">presence:</span><span class="plain-syntax"> </span><span class="identifier-syntax">hans</span><span class="plain-syntax">]</span>
<span class="plain-syntax">(2). +2 </span><span class="identifier-syntax">taking</span><span class="plain-syntax"> </span><span class="identifier-syntax">inventory</span><span class="plain-syntax"> [</span><span class="identifier-syntax">in</span><span class="plain-syntax">-</span><span class="identifier-syntax">presence:</span><span class="plain-syntax"> </span><span class="identifier-syntax">hans</span><span class="plain-syntax"> </span><span class="identifier-syntax">in</span><span class="plain-syntax"> </span><span class="identifier-syntax">the</span><span class="plain-syntax"> </span><span class="identifier-syntax">laboratory</span><span class="plain-syntax">]</span>
<span class="plain-syntax">(3). +2 </span><span class="identifier-syntax">taking</span><span class="plain-syntax"> [</span><span class="identifier-syntax">noun:</span><span class="plain-syntax"> </span><span class="identifier-syntax">inventory</span><span class="plain-syntax">] [</span><span class="identifier-syntax">in:</span><span class="plain-syntax"> </span><span class="identifier-syntax">the</span><span class="plain-syntax"> </span><span class="identifier-syntax">laboratory</span><span class="plain-syntax">] [</span><span class="identifier-syntax">in</span><span class="plain-syntax">-</span><span class="identifier-syntax">presence:</span><span class="plain-syntax"> </span><span class="identifier-syntax">hans</span><span class="plain-syntax">]</span>
<span class="plain-syntax">(4). +2 </span><span class="identifier-syntax">taking</span><span class="plain-syntax"> [</span><span class="identifier-syntax">noun:</span><span class="plain-syntax"> </span><span class="identifier-syntax">inventory</span><span class="plain-syntax">] [</span><span class="identifier-syntax">in</span><span class="plain-syntax">-</span><span class="identifier-syntax">presence:</span><span class="plain-syntax"> </span><span class="identifier-syntax">hans</span><span class="plain-syntax"> </span><span class="identifier-syntax">in</span><span class="plain-syntax"> </span><span class="identifier-syntax">the</span><span class="plain-syntax"> </span><span class="identifier-syntax">laboratory</span><span class="plain-syntax">]</span>
<span class="plain-syntax">(5). +2 </span><span class="identifier-syntax">taking</span><span class="plain-syntax"> [</span><span class="identifier-syntax">noun:</span><span class="plain-syntax"> </span><span class="identifier-syntax">inventory</span><span class="plain-syntax"> </span><span class="identifier-syntax">in</span><span class="plain-syntax"> </span><span class="identifier-syntax">the</span><span class="plain-syntax"> </span><span class="identifier-syntax">presence</span><span class="plain-syntax"> </span><span class="identifier-syntax">of</span><span class="plain-syntax"> </span><span class="identifier-syntax">hans</span><span class="plain-syntax">] [</span><span class="identifier-syntax">in:</span><span class="plain-syntax"> </span><span class="identifier-syntax">the</span><span class="plain-syntax"> </span><span class="identifier-syntax">laboratory</span><span class="plain-syntax">]</span>
<span class="plain-syntax">(6). +2 </span><span class="identifier-syntax">taking</span><span class="plain-syntax"> [</span><span class="identifier-syntax">noun:</span><span class="plain-syntax"> </span><span class="identifier-syntax">inventory</span><span class="plain-syntax"> </span><span class="identifier-syntax">in</span><span class="plain-syntax"> </span><span class="identifier-syntax">the</span><span class="plain-syntax"> </span><span class="identifier-syntax">presence</span><span class="plain-syntax"> </span><span class="identifier-syntax">of</span><span class="plain-syntax"> </span><span class="identifier-syntax">hans</span><span class="plain-syntax"> </span><span class="identifier-syntax">in</span><span class="plain-syntax"> </span><span class="identifier-syntax">the</span><span class="plain-syntax"> </span><span class="identifier-syntax">laboratory</span><span class="plain-syntax">]</span>
<span class="plain-syntax">(7). +0 </span><span class="identifier-syntax">looking</span>
</pre>
<p class="commentary">Note that it is ordered in such a way that actions with more fixed wording
occur before actions with fewer (at the same word position); and also that
the number of words inside the clauses increases as we go through possibilities
for each action. For (3) to (7), the "taking" options, the clause wording
runs to successively 4, 5, 8 and 9 words.
</p>

<p class="commentary">We now need to reduce this to a list of just two entries:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">(1). +2 </span><span class="identifier-syntax">taking</span><span class="plain-syntax"> </span><span class="identifier-syntax">inventory</span><span class="plain-syntax"> [</span><span class="identifier-syntax">in:</span><span class="plain-syntax"> </span><span class="identifier-syntax">the</span><span class="plain-syntax"> </span><span class="identifier-syntax">laboratory</span><span class="plain-syntax">] [</span><span class="identifier-syntax">in</span><span class="plain-syntax">-</span><span class="identifier-syntax">presence:</span><span class="plain-syntax"> </span><span class="identifier-syntax">hans</span><span class="plain-syntax">]</span>
<span class="plain-syntax">(2). +0 </span><span class="identifier-syntax">looking</span>
</pre>
<p class="commentary">An entry is "viable" if we can make sense of the text in all of its clauses.
As soon as we find a viable entry at a given word position, we ignore all
subsequent possibilities at that position &mdash; so the ordering of the ANL is
crucial: options near the top of the list are preferred to those lower down.
</p>

<p class="commentary"><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Reduce the list to the first viable entry at each word position</span><span class="named-paragraph-number">1.1</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="reserved-syntax">anl_entry</span><span class="plain-syntax"> *</span><span class="identifier-syntax">viable</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">; </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">at</span><span class="plain-syntax"> = -1;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">LOOP_THROUGH_ANL</span><span class="plain-syntax">(</span><span class="identifier-syntax">entry</span><span class="plain-syntax">, </span><span class="identifier-syntax">list</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><a href="4-anl.html#SP22" class="function-link"><span class="function-syntax">ActionNameLists::word_position</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">entry</span><span class="plain-syntax">) != </span><span class="identifier-syntax">at</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">at</span><span class="plain-syntax"> &gt;= </span><span class="constant-syntax">0</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">viable</span><span class="plain-syntax"> == </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">)) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">at</span><span class="plain-syntax"> = </span><a href="4-anl.html#SP22" class="function-link"><span class="function-syntax">ActionNameLists::word_position</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">entry</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">viable</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">viable</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">                </span><a href="4-anl.html#SP5" class="function-link"><span class="function-syntax">ActionNameLists::mark_for_deletion</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">entry</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">continue</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            }</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">action_name</span><span class="plain-syntax"> *</span><span class="identifier-syntax">an</span><span class="plain-syntax"> = </span><a href="4-anl.html#SP13" class="function-link"><span class="function-syntax">ActionNameLists::action</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">entry</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">fail</span><span class="plain-syntax"> = </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">, </span><span class="identifier-syntax">entry_options</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="named-paragraph-container code-font"><a href="4-pc.html#SP1_1_1" class="named-paragraph-link"><span class="named-paragraph">Parse the clauses</span><span class="named-paragraph-number">1.1.1</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">fail</span><span class="plain-syntax">) { </span><a href="4-anl.html#SP5" class="function-link"><span class="function-syntax">ActionNameLists::mark_for_deletion</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">entry</span><span class="plain-syntax">); </span><span class="reserved-syntax">continue</span><span class="plain-syntax">; }</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">PluginCalls::act_on_ANL_entry_options</span><span class="plain-syntax">(</span><span class="identifier-syntax">entry</span><span class="plain-syntax">, </span><span class="identifier-syntax">entry_options</span><span class="plain-syntax">, &amp;</span><span class="identifier-syntax">fail</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">fail</span><span class="plain-syntax">) { </span><a href="4-anl.html#SP5" class="function-link"><span class="function-syntax">ActionNameLists::mark_for_deletion</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">entry</span><span class="plain-syntax">); </span><span class="reserved-syntax">continue</span><span class="plain-syntax">; }</span>
<span class="plain-syntax">        </span><span class="named-paragraph-container code-font"><a href="4-pc.html#SP1_1_2" class="named-paragraph-link"><span class="named-paragraph">Typecheck or otherwise validate the clauses</span><span class="named-paragraph-number">1.1.2</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">fail</span><span class="plain-syntax">) { </span><a href="4-anl.html#SP5" class="function-link"><span class="function-syntax">ActionNameLists::mark_for_deletion</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">entry</span><span class="plain-syntax">); </span><span class="reserved-syntax">continue</span><span class="plain-syntax">; }</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">viable</span><span class="plain-syntax"> = </span><span class="identifier-syntax">entry</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">viable</span><span class="plain-syntax"> == </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><a href="4-anl.html#SP6" class="function-link"><span class="function-syntax">ActionNameLists::remove_entries_marked_for_deletion</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">list</span><span class="plain-syntax">);</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="4-pc.html#SP1">&#167;1</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP1_1_1" class="paragraph-anchor"></a><b>&#167;1.1.1. </b>Now each clause's text must be evaluated: for example, on the clause
<span class="extract"><span class="extract-syntax">[in-presence: hans]</span></span> we will have to evaluate "Hans".
</p>

<p class="commentary">Note the special case for actions whose second noun has the kind <span class="extract"><span class="extract-syntax">K_understanding</span></span>,
meaning that they hold topics of conversation ("ask Hans about cosmic rays").
There is ordinarily no way in Inform to write a literal of this kind, but here
we are allowed to write a text literal instead, and it is automatically converted.
</p>

<p class="commentary"><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Parse the clauses</span><span class="named-paragraph-number">1.1.1</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">saved_pap</span><span class="plain-syntax"> = </span><span class="identifier-syntax">pap_failure_reason</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">LOOP_THROUGH_ANL_CLAUSES</span><span class="plain-syntax">(</span><span class="identifier-syntax">c</span><span class="plain-syntax">, </span><span class="identifier-syntax">entry</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">fail</span><span class="plain-syntax">) </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">LOG_INDENT</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">Log::aspect_switched_on</span><span class="plain-syntax">(</span><span class="constant-syntax">ACTION_PATTERN_PARSING_DA</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">LOG</span><span class="plain-syntax">(</span><span class="string-syntax">"parsing "</span><span class="plain-syntax">); </span><a href="4-anl.html#SP27" class="function-link"><span class="function-syntax">ActionNameLists::log_clause</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">c</span><span class="plain-syntax">); </span><span class="identifier-syntax">LOG</span><span class="plain-syntax">(</span><span class="string-syntax">" - "</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">Wordings::nonempty</span><span class="plain-syntax">(</span><span class="identifier-syntax">c</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">clause_text</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">opts</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">; </span><span class="identifier-syntax">PluginCalls::parse_AP_clause</span><span class="plain-syntax">(</span><span class="identifier-syntax">an</span><span class="plain-syntax">, </span><span class="identifier-syntax">c</span><span class="plain-syntax">, &amp;</span><span class="identifier-syntax">opts</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">opts</span><span class="plain-syntax"> != </span><span class="constant-syntax">0</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">entry_options</span><span class="plain-syntax"> |= </span><span class="identifier-syntax">opts</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">c</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">clause_ID</span><span class="plain-syntax"> == </span><span class="constant-syntax">SECOND_AP_CLAUSE</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">an</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">K_understanding</span><span class="plain-syntax">) &amp;&amp;</span>
<span class="plain-syntax">                (</span><span class="identifier-syntax">Kinds::eq</span><span class="plain-syntax">(</span><a href="4-as.html#SP4" class="function-link"><span class="function-syntax">ActionSemantics::kind_of_second</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">an</span><span class="plain-syntax">), </span><span class="identifier-syntax">K_understanding</span><span class="plain-syntax">)) &amp;&amp;</span>
<span class="plain-syntax">                (</span><span class="function-syntax">&lt;understanding-action-irregular-operand&gt;(c-&gt;</span><span class="element-syntax">clause_text</span><span class="plain-syntax">))) {</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">parse_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">val</span><span class="plain-syntax"> = </span><a href="5-pp.html#SP4" class="function-link"><span class="function-syntax">ParsingPlugin::rvalue_from_command_grammar</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">NULL</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">Node::set_text</span><span class="plain-syntax">(</span><span class="identifier-syntax">val</span><span class="plain-syntax">, </span><span class="identifier-syntax">c</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">clause_text</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">c</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">evaluation</span><span class="plain-syntax"> = </span><span class="identifier-syntax">val</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="function-syntax">&lt;action-operand&gt;(c-&gt;</span><span class="element-syntax">clause_text</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="function-syntax">&lt;&lt;r&gt;&gt;</span><span class="plain-syntax">) </span><span class="identifier-syntax">c</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">evaluation</span><span class="plain-syntax"> = </span><span class="function-syntax">&lt;&lt;rp&gt;&gt;</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="identifier-syntax">c</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">evaluation</span><span class="plain-syntax"> = </span><span class="identifier-syntax">Specifications::from_kind</span><span class="plain-syntax">(</span><span class="identifier-syntax">K_thing</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">fail</span><span class="plain-syntax"> = </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            }</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">K_understanding</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">Rvalues::is_CONSTANT_of_kind</span><span class="plain-syntax">(</span><span class="identifier-syntax">c</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">evaluation</span><span class="plain-syntax">, </span><span class="identifier-syntax">K_text</span><span class="plain-syntax">)))</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">Node::set_kind_of_value</span><span class="plain-syntax">(</span><span class="identifier-syntax">c</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">evaluation</span><span class="plain-syntax">, </span><span class="identifier-syntax">K_understanding</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">Log::aspect_switched_on</span><span class="plain-syntax">(</span><span class="constant-syntax">ACTION_PATTERN_PARSING_DA</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">fail</span><span class="plain-syntax">) </span><span class="identifier-syntax">LOG</span><span class="plain-syntax">(</span><span class="string-syntax">"fail\n"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="identifier-syntax">LOG</span><span class="plain-syntax">(</span><span class="string-syntax">"$P\n"</span><span class="plain-syntax">, </span><span class="identifier-syntax">c</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">evaluation</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">LOG_OUTDENT</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">pap_failure_reason</span><span class="plain-syntax"> = </span><span class="identifier-syntax">saved_pap</span><span class="plain-syntax">;</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="4-pc.html#SP1_1">&#167;1.1</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP2" class="paragraph-anchor"></a><b>&#167;2. </b>The "operands" of an action pattern are the nouns to which it applies: for
example, in "Kevin taking or dropping something", the operand is "something".
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="function-syntax">&lt;action-operand&gt;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">something</span><span class="plain-syntax">/</span><span class="identifier-syntax">anything</span><span class="plain-syntax"> |</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">something</span><span class="plain-syntax">/</span><span class="identifier-syntax">anything</span><span class="plain-syntax"> </span><span class="reserved-syntax">else</span><span class="plain-syntax"> |</span>
<span class="plain-syntax">    </span><span class="function-syntax">&lt;s-ap-parameter&gt;</span>

<span class="function-syntax">&lt;understanding-action-irregular-operand&gt;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">something</span><span class="plain-syntax">/</span><span class="identifier-syntax">anything</span><span class="plain-syntax"> |</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">it</span>
</pre>
<p class="commentary firstcommentary"><a id="SP1_1_2" class="paragraph-anchor"></a><b>&#167;1.1.2. </b>Supposing that we managed to find values for each clause, we might still
have impossible ones: "putting 101 on false", say, where the noun seems to
be the number 101 and the second noun the truth state "false". So we need
to typecheck each clause.
</p>

<p class="commentary"><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Typecheck or otherwise validate the clauses</span><span class="named-paragraph-number">1.1.2</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">LOOP_THROUGH_ANL_CLAUSES</span><span class="plain-syntax">(</span><span class="identifier-syntax">c</span><span class="plain-syntax">, </span><span class="identifier-syntax">entry</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">fail</span><span class="plain-syntax">) </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">LOG_INDENT</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">Log::aspect_switched_on</span><span class="plain-syntax">(</span><span class="constant-syntax">ACTION_PATTERN_PARSING_DA</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">LOG</span><span class="plain-syntax">(</span><span class="string-syntax">"validating "</span><span class="plain-syntax">); </span><a href="4-anl.html#SP27" class="function-link"><span class="function-syntax">ActionNameLists::log_clause</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">c</span><span class="plain-syntax">); </span><span class="identifier-syntax">LOG</span><span class="plain-syntax">(</span><span class="string-syntax">" - "</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">kind</span><span class="plain-syntax"> *</span><span class="identifier-syntax">check</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">switch</span><span class="plain-syntax"> (</span><span class="identifier-syntax">c</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">clause_ID</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">NOUN_AP_CLAUSE:</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">check</span><span class="plain-syntax"> = </span><span class="identifier-syntax">K_object</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">an</span><span class="plain-syntax">) </span><span class="identifier-syntax">check</span><span class="plain-syntax"> = </span><a href="4-as.html#SP4" class="function-link"><span class="function-syntax">ActionSemantics::kind_of_noun</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">an</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">SECOND_AP_CLAUSE:</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">check</span><span class="plain-syntax"> = </span><span class="identifier-syntax">K_object</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">an</span><span class="plain-syntax">) </span><span class="identifier-syntax">check</span><span class="plain-syntax"> = </span><a href="4-as.html#SP4" class="function-link"><span class="function-syntax">ActionSemantics::kind_of_second</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">an</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">IN_AP_CLAUSE:</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">check</span><span class="plain-syntax"> = </span><span class="identifier-syntax">K_object</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">IN_THE_PRESENCE_OF_AP_CLAUSE:</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">check</span><span class="plain-syntax"> = </span><span class="identifier-syntax">K_object</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">c</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">stv_to_match</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">rv</span><span class="plain-syntax"> = </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">PluginCalls::validate_AP_clause</span><span class="plain-syntax">(</span><span class="identifier-syntax">an</span><span class="plain-syntax">, </span><span class="identifier-syntax">c</span><span class="plain-syntax">, &amp;</span><span class="identifier-syntax">rv</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">Log::aspect_switched_on</span><span class="plain-syntax">(</span><span class="constant-syntax">ACTION_PATTERN_PARSING_DA</span><span class="plain-syntax">))</span>
<span class="plain-syntax">                    </span><span class="identifier-syntax">LOG</span><span class="plain-syntax">(</span><span class="string-syntax">"referred to feature - "</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">rv</span><span class="plain-syntax"> == </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">                    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">Log::aspect_switched_on</span><span class="plain-syntax">(</span><span class="constant-syntax">ACTION_PATTERN_PARSING_DA</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">                        </span><span class="identifier-syntax">LOG</span><span class="plain-syntax">(</span><span class="string-syntax">"failed badly with problem\n"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                    }</span>
<span class="plain-syntax">                    </span><span class="identifier-syntax">LOG_OUTDENT</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                }</span>
<span class="plain-syntax">            } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">check</span><span class="plain-syntax"> = </span><span class="identifier-syntax">SharedVariables::get_kind</span><span class="plain-syntax">(</span><span class="identifier-syntax">c</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">stv_to_match</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            }</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">Node::is</span><span class="plain-syntax">(</span><span class="identifier-syntax">c</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">evaluation</span><span class="plain-syntax">, </span><span class="identifier-syntax">UNKNOWN_NT</span><span class="plain-syntax">)) </span><span class="identifier-syntax">fail</span><span class="plain-syntax"> = </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">Log::aspect_switched_on</span><span class="plain-syntax">(</span><span class="constant-syntax">ACTION_PATTERN_PARSING_DA</span><span class="plain-syntax">))</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">LOG</span><span class="plain-syntax">(</span><span class="string-syntax">"using Dash with kind %u - "</span><span class="plain-syntax">, </span><span class="identifier-syntax">check</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">check</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">Dash::validate_parameter</span><span class="plain-syntax">(</span><span class="identifier-syntax">c</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">evaluation</span><span class="plain-syntax">, </span><span class="identifier-syntax">check</span><span class="plain-syntax">) == </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">))</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">fail</span><span class="plain-syntax"> = </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">Log::aspect_switched_on</span><span class="plain-syntax">(</span><span class="constant-syntax">ACTION_PATTERN_PARSING_DA</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">fail</span><span class="plain-syntax">) </span><span class="identifier-syntax">LOG</span><span class="plain-syntax">(</span><span class="string-syntax">"fail\n"</span><span class="plain-syntax">); </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="identifier-syntax">LOG</span><span class="plain-syntax">(</span><span class="string-syntax">"pass\n"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">LOG_OUTDENT</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="4-pc.html#SP1_1">&#167;1.1</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP1_2" class="paragraph-anchor"></a><b>&#167;1.2. </b>This is where heterogeneous patterns like "dropping a thing or taking a
container" are thrown out: only the last-placed action is allowed to have
clauses.
</p>

<p class="commentary"><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Reject the resulting list if two or more entries contain clauses</span><span class="named-paragraph-number">1.2</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">N</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">LOOP_THROUGH_ANL</span><span class="plain-syntax">(</span><span class="identifier-syntax">entry</span><span class="plain-syntax">, </span><span class="identifier-syntax">list</span><span class="plain-syntax">)</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">entry</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">parsing_data</span><span class="plain-syntax">.</span><span class="element-syntax">anl_clauses</span><span class="plain-syntax">)</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">N</span><span class="plain-syntax">++;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">N</span><span class="plain-syntax"> &gt; </span><span class="constant-syntax">1</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">pap_failure_reason</span><span class="plain-syntax"> = </span><span class="constant-syntax">MIXEDNOUNS_PAPF</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">LOGIF</span><span class="plain-syntax">(</span><span class="identifier-syntax">ACTION_PATTERN_PARSING</span><span class="plain-syntax">, </span><span class="string-syntax">"Rejecting with mixed nouns\n"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="4-pc.html#SP1">&#167;1</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP1_3" class="paragraph-anchor"></a><b>&#167;1.3. </b>And this is where impossible mixtures of actions are thrown out: for
example, if there is an action "setting" whose noun is a number, then
"taking or setting 50" will be thrown out because the two actions here
disagree about the meaning of the noun.
</p>

<p class="commentary">Similarly, "looking or taking a vehicle" is thrown out because looking has
no noun.
</p>

<p class="commentary">This is done in the interests of having a type-safe way to compile the
pattern check, but really it also avoids allowing action patterns which
look like syllepses.
</p>

<p class="commentary"><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Reject the resulting list if, given the clauses, two actions are immiscible</span><span class="named-paragraph-number">1.3</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">immiscible</span><span class="plain-syntax"> = </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">, </span><span class="identifier-syntax">no_oow</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">, </span><span class="identifier-syntax">no_iw</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">, </span><span class="identifier-syntax">no_of_pars</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>

<span class="plain-syntax">    </span><span class="identifier-syntax">kind</span><span class="plain-syntax"> *</span><span class="identifier-syntax">kinds_observed_in_list</span><span class="plain-syntax">[2];</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">kinds_observed_in_list</span><span class="plain-syntax">[0] = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">kinds_observed_in_list</span><span class="plain-syntax">[1] = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">LOOP_THROUGH_ANL</span><span class="plain-syntax">(</span><span class="identifier-syntax">entry</span><span class="plain-syntax">, </span><span class="identifier-syntax">list</span><span class="plain-syntax">)</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><a href="4-anl.html#SP13" class="function-link"><span class="function-syntax">ActionNameLists::nap</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">entry</span><span class="plain-syntax">) == </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">nouns_in_entry</span><span class="plain-syntax"> = </span><a href="4-anl.html#SP17" class="function-link"><span class="function-syntax">ActionNameLists::noun_count</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">entry</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">nouns_in_entry</span><span class="plain-syntax"> &gt; </span><span class="constant-syntax">0</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">no_of_pars</span><span class="plain-syntax"> &gt; </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="identifier-syntax">immiscible</span><span class="plain-syntax"> = </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">no_of_pars</span><span class="plain-syntax"> = </span><span class="identifier-syntax">nouns_in_entry</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            }</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">action_name</span><span class="plain-syntax"> *</span><span class="identifier-syntax">this</span><span class="plain-syntax"> = </span><a href="4-anl.html#SP13" class="function-link"><span class="function-syntax">ActionNameLists::action</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">entry</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">this</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><a href="4-as.html#SP4" class="function-link"><span class="function-syntax">ActionSemantics::is_out_of_world</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">this</span><span class="plain-syntax">)) </span><span class="identifier-syntax">no_oow</span><span class="plain-syntax">++; </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="identifier-syntax">no_iw</span><span class="plain-syntax">++;</span>

<span class="plain-syntax">                </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">nouns_in_entry</span><span class="plain-syntax"> &gt;= </span><span class="constant-syntax">1</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">                    </span><span class="identifier-syntax">kind</span><span class="plain-syntax"> *</span><span class="identifier-syntax">K</span><span class="plain-syntax"> = </span><a href="4-as.html#SP4" class="function-link"><span class="function-syntax">ActionSemantics::kind_of_noun</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">this</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                    </span><span class="identifier-syntax">kind</span><span class="plain-syntax"> *</span><span class="identifier-syntax">A</span><span class="plain-syntax"> = </span><span class="identifier-syntax">kinds_observed_in_list</span><span class="plain-syntax">[0];</span>
<span class="plain-syntax">                    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">A</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">K</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">Kinds::eq</span><span class="plain-syntax">(</span><span class="identifier-syntax">A</span><span class="plain-syntax">, </span><span class="identifier-syntax">K</span><span class="plain-syntax">) == </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">))</span>
<span class="plain-syntax">                        </span><span class="identifier-syntax">immiscible</span><span class="plain-syntax"> = </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                    </span><span class="identifier-syntax">kinds_observed_in_list</span><span class="plain-syntax">[0] = </span><span class="identifier-syntax">K</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                }</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">nouns_in_entry</span><span class="plain-syntax"> &gt;= </span><span class="constant-syntax">2</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">                    </span><span class="identifier-syntax">kind</span><span class="plain-syntax"> *</span><span class="identifier-syntax">K</span><span class="plain-syntax"> = </span><a href="4-as.html#SP4" class="function-link"><span class="function-syntax">ActionSemantics::kind_of_second</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">this</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                    </span><span class="identifier-syntax">kind</span><span class="plain-syntax"> *</span><span class="identifier-syntax">A</span><span class="plain-syntax"> = </span><span class="identifier-syntax">kinds_observed_in_list</span><span class="plain-syntax">[1];</span>
<span class="plain-syntax">                    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">A</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">K</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">Kinds::eq</span><span class="plain-syntax">(</span><span class="identifier-syntax">A</span><span class="plain-syntax">, </span><span class="identifier-syntax">K</span><span class="plain-syntax">) == </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">))</span>
<span class="plain-syntax">                        </span><span class="identifier-syntax">immiscible</span><span class="plain-syntax"> = </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                    </span><span class="identifier-syntax">kinds_observed_in_list</span><span class="plain-syntax">[1] = </span><span class="identifier-syntax">K</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                }</span>
<span class="plain-syntax">            }</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">no_oow</span><span class="plain-syntax"> &gt; </span><span class="constant-syntax">0</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">no_iw</span><span class="plain-syntax"> &gt; </span><span class="constant-syntax">0</span><span class="plain-syntax">)) </span><span class="identifier-syntax">immiscible</span><span class="plain-syntax"> = </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">;</span>

<span class="plain-syntax">    </span><span class="identifier-syntax">LOOP_THROUGH_ANL</span><span class="plain-syntax">(</span><span class="identifier-syntax">entry</span><span class="plain-syntax">, </span><span class="identifier-syntax">list</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">action_name</span><span class="plain-syntax"> *</span><span class="identifier-syntax">an</span><span class="plain-syntax"> = </span><a href="4-anl.html#SP13" class="function-link"><span class="function-syntax">ActionNameLists::action</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">entry</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">an</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">no_of_pars</span><span class="plain-syntax"> &gt;= </span><span class="constant-syntax">1</span><span class="plain-syntax">) &amp;&amp; (</span><a href="4-as.html#SP4" class="function-link"><span class="function-syntax">ActionSemantics::can_have_noun</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">an</span><span class="plain-syntax">) == </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">))</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">immiscible</span><span class="plain-syntax"> = </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">no_of_pars</span><span class="plain-syntax"> &gt;= </span><span class="constant-syntax">2</span><span class="plain-syntax">) &amp;&amp; (</span><a href="4-as.html#SP4" class="function-link"><span class="function-syntax">ActionSemantics::can_have_second</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">an</span><span class="plain-syntax">) == </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">))</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">immiscible</span><span class="plain-syntax"> = </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">    }</span>

<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">immiscible</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">pap_failure_reason</span><span class="plain-syntax"> = </span><span class="constant-syntax">IMMISCIBLE_PAPF</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">LOGIF</span><span class="plain-syntax">(</span><span class="identifier-syntax">ACTION_PATTERN_PARSING</span><span class="plain-syntax">, </span><span class="string-syntax">"Rejecting with immiscible actions\n"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="4-pc.html#SP1">&#167;1</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP1_4" class="paragraph-anchor"></a><b>&#167;1.4. </b>Fanfares and trumpets voluntary:
</p>

<p class="commentary"><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Produce and return an action pattern from what survives of the list</span><span class="named-paragraph-number">1.4</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="reserved-syntax">action_pattern</span><span class="plain-syntax"> *</span><span class="identifier-syntax">ap</span><span class="plain-syntax"> = </span><a href="4-ap2.html#SP4" class="function-link"><span class="function-syntax">ActionPatterns::new</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">W</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">anl_item</span><span class="plain-syntax"> *</span><span class="identifier-syntax">first</span><span class="plain-syntax"> = </span><a href="4-anl.html#SP12" class="function-link"><span class="function-syntax">ActionNameLists::first_item</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">list</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">first</span><span class="plain-syntax">) &amp;&amp; ((</span><span class="identifier-syntax">first</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">action_listed</span><span class="plain-syntax">) || (</span><span class="identifier-syntax">first</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">nap_listed</span><span class="plain-syntax">))) </span><span class="identifier-syntax">ap</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">action_list</span><span class="plain-syntax"> = </span><span class="identifier-syntax">list</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">LOOP_THROUGH_ANL</span><span class="plain-syntax">(</span><span class="identifier-syntax">entry</span><span class="plain-syntax">, </span><span class="identifier-syntax">list</span><span class="plain-syntax">)</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">LOOP_THROUGH_ANL_CLAUSES</span><span class="plain-syntax">(</span><span class="identifier-syntax">c</span><span class="plain-syntax">, </span><span class="identifier-syntax">entry</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">LOGIF</span><span class="plain-syntax">(</span><span class="identifier-syntax">ACTION_PATTERN_PARSING</span><span class="plain-syntax">,</span>
<span class="plain-syntax">                </span><span class="string-syntax">"Succeeds with clause %d = '%W'\n"</span><span class="plain-syntax">, </span><span class="identifier-syntax">c</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">clause_ID</span><span class="plain-syntax">, </span><span class="identifier-syntax">c</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">clause_text</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">c</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">stv_to_match</span><span class="plain-syntax">)</span>
<span class="plain-syntax">                </span><a href="4-apc.html#SP14" class="function-link"><span class="function-syntax">APClauses::set_action_variable_spec</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">ap</span><span class="plain-syntax">, </span><span class="identifier-syntax">c</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">stv_to_match</span><span class="plain-syntax">, </span><span class="identifier-syntax">c</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">evaluation</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">else</span>
<span class="plain-syntax">                </span><a href="4-apc.html#SP7" class="function-link"><span class="function-syntax">APClauses::set_spec</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">ap</span><span class="plain-syntax">, </span><span class="identifier-syntax">c</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">clause_ID</span><span class="plain-syntax">, </span><span class="identifier-syntax">c</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">evaluation</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">ap</span><span class="plain-syntax">;</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="4-pc.html#SP1">&#167;1</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP3" class="paragraph-anchor"></a><b>&#167;3. Internal test.</b>This is an all-singing, all-dancing way to test Level 7 and, along with it, the
action name list parser. In effect, there's a cutesy mini-language for what you
can express in the test wording.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">ParseClauses::perform_pattern_internal_test</span><button class="popup" onclick="togglePopup('usagePopup2')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup2">Usage of <span class="code-font"><span class="function-syntax">ParseClauses::perform_pattern_internal_test</span></span>:<br/>IF Module - <a href="1-im.html#SP2">&#167;2</a></span></button><span class="plain-syntax">(</span><span class="identifier-syntax">OUTPUT_STREAM</span><span class="plain-syntax">,</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="identifier-syntax">internal_test_case</span><span class="plain-syntax"> *</span><span class="identifier-syntax">itc</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">saved</span><span class="plain-syntax"> = </span><a href="4-pap.html#SP2" class="function-link"><span class="function-syntax">ParseActionPatterns::enter_mode</span></a><span class="plain-syntax">(</span><span class="constant-syntax">PERMIT_TRYING_OMISSION</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="function-syntax">&lt;perform-ap-test&gt;(itc-&gt;</span><span class="identifier-syntax">text_supplying_the_case</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><a href="4-pap.html#SP2" class="function-link"><span class="function-syntax">ParseActionPatterns::restore_mode</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">saved</span><span class="plain-syntax">);</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP4" class="paragraph-anchor"></a><b>&#167;4. </b>The mini-language is interpreted: to parse it is to run it. Notably, it also
enables named action patterns to be created, so that we can then parse them
back again:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="function-syntax">&lt;perform-ap-test&gt;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">list</span><span class="plain-syntax"> {...} |</span>
<span class="plain-syntax">    </span><span class="function-syntax">&lt;test-ap&gt;</span><span class="plain-syntax"> |</span>
<span class="plain-syntax">    </span><span class="function-syntax">&lt;test-ap&gt;</span><span class="plain-syntax"> ~~ </span><span class="function-syntax">&lt;test-ap&gt;</span><span class="plain-syntax"> |</span>
<span class="plain-syntax">    ...</span>

<span class="function-syntax">&lt;test-ap&gt;</span>
<span class="plain-syntax">    </span><span class="function-syntax">&lt;test-ap&gt;</span><span class="plain-syntax"> </span><span class="identifier-syntax">is</span><span class="plain-syntax"> {...} |</span>
<span class="plain-syntax">    </span><span class="function-syntax">&lt;test-register&gt;</span><span class="plain-syntax"> = </span><span class="function-syntax">&lt;test-ap&gt;</span><span class="plain-syntax"> |</span>
<span class="plain-syntax">    </span><span class="function-syntax">&lt;action-pattern&gt;</span><span class="plain-syntax"> |</span>
<span class="plain-syntax">    </span><span class="function-syntax">&lt;test-register&gt;</span><span class="plain-syntax"> |</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">experimental</span><span class="plain-syntax"> {...}</span>

<span class="function-syntax">&lt;test-register&gt;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">r1</span><span class="plain-syntax"> | </span><span class="identifier-syntax">r2</span><span class="plain-syntax"> | </span><span class="identifier-syntax">r3</span><span class="plain-syntax"> | </span><span class="identifier-syntax">r4</span><span class="plain-syntax"> | </span><span class="identifier-syntax">r5</span>
</pre>
<p class="commentary firstcommentary"><a id="SP4_1" class="paragraph-anchor"></a><b>&#167;4.1. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Write textual AP test result</span><span class="named-paragraph-number">4.1</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">LOG</span><span class="plain-syntax">(</span><span class="string-syntax">"%W: $A\n"</span><span class="plain-syntax">, </span><span class="identifier-syntax">W</span><span class="plain-syntax">, </span><span class="identifier-syntax">RP</span><span class="plain-syntax">[1]);</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="4-pc.html#SP4">&#167;4</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP4_2" class="paragraph-anchor"></a><b>&#167;4.2. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Write comparison AP test result</span><span class="named-paragraph-number">4.2</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">rv</span><span class="plain-syntax"> = </span><a href="4-ap2.html#SP10" class="function-link"><span class="function-syntax">ActionPatterns::compare_specificity</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">RP</span><span class="plain-syntax">[1], </span><span class="identifier-syntax">RP</span><span class="plain-syntax">[2]);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">rv_converse</span><span class="plain-syntax"> = </span><a href="4-ap2.html#SP10" class="function-link"><span class="function-syntax">ActionPatterns::compare_specificity</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">RP</span><span class="plain-syntax">[2], </span><span class="identifier-syntax">RP</span><span class="plain-syntax">[1]);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">LOG</span><span class="plain-syntax">(</span><span class="string-syntax">"%W: "</span><span class="plain-syntax">, </span><span class="identifier-syntax">W</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">rv</span><span class="plain-syntax"> &gt; </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="identifier-syntax">LOG</span><span class="plain-syntax">(</span><span class="string-syntax">"left is more specific\n"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">rv</span><span class="plain-syntax"> &lt; </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="identifier-syntax">LOG</span><span class="plain-syntax">(</span><span class="string-syntax">"right is more specific\n"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">rv</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="identifier-syntax">LOG</span><span class="plain-syntax">(</span><span class="string-syntax">"equally specific\n"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">rv_converse</span><span class="plain-syntax"> != -1*</span><span class="identifier-syntax">rv</span><span class="plain-syntax">) </span><span class="identifier-syntax">LOG</span><span class="plain-syntax">(</span><span class="string-syntax">"*** Not antisymmetric ***\n"</span><span class="plain-syntax">);</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="4-pc.html#SP4">&#167;4</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP4_3" class="paragraph-anchor"></a><b>&#167;4.3. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Write failure</span><span class="named-paragraph-number">4.3</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">LOG</span><span class="plain-syntax">(</span><span class="string-syntax">"%W: failed to parse\n"</span><span class="plain-syntax">, </span><span class="identifier-syntax">W</span><span class="plain-syntax">);</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="4-pc.html#SP4">&#167;4</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP4_4" class="paragraph-anchor"></a><b>&#167;4.4. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Make a named action pattern</span><span class="named-paragraph-number">4.4</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">wording</span><span class="plain-syntax"> </span><span class="identifier-syntax">W</span><span class="plain-syntax"> = </span><span class="identifier-syntax">GET_RW</span><span class="plain-syntax">(</span><span class="function-syntax">&lt;test-ap&gt;</span><span class="plain-syntax">, </span><span class="constant-syntax">1</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">named_action_pattern</span><span class="plain-syntax"> *</span><span class="identifier-syntax">nap</span><span class="plain-syntax"> = </span><a href="4-nap.html#SP3" class="function-link"><span class="function-syntax">NamedActionPatterns::add</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">RP</span><span class="plain-syntax">[1], </span><span class="identifier-syntax">W</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">action_pattern</span><span class="plain-syntax"> *</span><span class="identifier-syntax">new_ap</span><span class="plain-syntax"> = </span><a href="4-ap2.html#SP4" class="function-link"><span class="function-syntax">ActionPatterns::new</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">W</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">anl_entry</span><span class="plain-syntax"> *</span><span class="identifier-syntax">entry</span><span class="plain-syntax"> = </span><a href="4-anl.html#SP4" class="function-link"><span class="function-syntax">ActionNameLists::new_entry_at</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">W</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">entry</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">item</span><span class="plain-syntax">.</span><span class="element-syntax">nap_listed</span><span class="plain-syntax"> = </span><span class="identifier-syntax">nap</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">new_ap</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">action_list</span><span class="plain-syntax"> = </span><a href="4-anl.html#SP1" class="function-link"><span class="function-syntax">ActionNameLists::new_list</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">entry</span><span class="plain-syntax">, </span><span class="constant-syntax">ANL_POSITIVE</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    ==&gt; { -, </span><span class="identifier-syntax">new_ap</span><span class="plain-syntax"> };</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="4-pc.html#SP4">&#167;4</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP5" class="paragraph-anchor"></a><b>&#167;5. </b>This mini-language has a set of 5 "registers", which are really variables,
for stashing test results for use in subsequent tests:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">ap_test_register_initialised</span><span class="plain-syntax"> = </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="reserved-syntax">action_pattern</span><span class="plain-syntax"> *</span><span class="identifier-syntax">ap_test_register</span><span class="plain-syntax">[5];</span>

<span class="reserved-syntax">action_pattern</span><span class="plain-syntax"> *</span><span class="function-syntax">ParseClauses::read_reg</span><button class="popup" onclick="togglePopup('usagePopup3')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup3">Usage of <span class="code-font"><span class="function-syntax">ParseClauses::read_reg</span></span>:<br/><a href="4-pc.html#SP4">&#167;4</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">r</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">r</span><span class="plain-syntax"> &lt; </span><span class="constant-syntax">0</span><span class="plain-syntax">) || (</span><span class="identifier-syntax">r</span><span class="plain-syntax"> &gt;= </span><span class="constant-syntax">5</span><span class="plain-syntax">)) </span><span class="identifier-syntax">internal_error</span><span class="plain-syntax">(</span><span class="string-syntax">"bad AP register"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">ap_test_register_initialised</span><span class="plain-syntax"> == </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">ap_test_register_initialised</span><span class="plain-syntax"> = </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">i</span><span class="plain-syntax">=0; </span><span class="identifier-syntax">i</span><span class="plain-syntax">&lt;5; </span><span class="identifier-syntax">i</span><span class="plain-syntax">++) </span><span class="identifier-syntax">ap_test_register</span><span class="plain-syntax">[</span><span class="identifier-syntax">i</span><span class="plain-syntax">] = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">ap_test_register</span><span class="plain-syntax">[</span><span class="identifier-syntax">r</span><span class="plain-syntax">];</span>
<span class="plain-syntax">}</span>

<span class="reserved-syntax">action_pattern</span><span class="plain-syntax"> *</span><span class="function-syntax">ParseClauses::set_reg</span><button class="popup" onclick="togglePopup('usagePopup4')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup4">Usage of <span class="code-font"><span class="function-syntax">ParseClauses::set_reg</span></span>:<br/><a href="4-pc.html#SP4">&#167;4</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">r</span><span class="plain-syntax">, </span><span class="reserved-syntax">action_pattern</span><span class="plain-syntax"> *</span><span class="identifier-syntax">ap</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><a href="4-pc.html#SP5" class="function-link"><span class="function-syntax">ParseClauses::read_reg</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">r</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">ap_test_register</span><span class="plain-syntax">[</span><span class="identifier-syntax">r</span><span class="plain-syntax">] = </span><span class="identifier-syntax">ap</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><a href="4-pc.html#SP5" class="function-link"><span class="function-syntax">ParseClauses::read_reg</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">r</span><span class="plain-syntax">);</span>
<span class="plain-syntax">}</span>
</pre>
<nav role="progress"><div class="progresscontainer">
    <ul class="progressbar"><li class="progressprev"><a href="4-pap.html">&#10094;</a></li><li class="progresschapter"><a href="P-wtmd.html">P</a></li><li class="progresschapter"><a href="1-im.html">1</a></li><li class="progresschapter"><a href="2-bd.html">2</a></li><li class="progresschapter"><a href="3-sm.html">3</a></li><li class="progresscurrentchapter">4</li><li class="progresssection"><a href="4-ap.html">ap</a></li><li class="progresssection"><a href="4-anaa.html">anaa</a></li><li class="progresssection"><a href="4-ak.html">ak</a></li><li class="progresssection"><a href="4-ac.html">ac</a></li><li class="progresssection"><a href="4-act.html">act</a></li><li class="progresssection"><a href="4-as.html">as</a></li><li class="progresssection"><a href="4-av.html">av</a></li><li class="progresssection"><a href="4-ann.html">ann</a></li><li class="progresssection"><a href="4-ap2.html">ap2</a></li><li class="progresssection"><a href="4-anl.html">anl</a></li><li class="progresssection"><a href="4-apc.html">apc</a></li><li class="progresssection"><a href="4-pap.html">pap</a></li><li class="progresscurrent">pc</li><li class="progresssection"><a href="4-ea.html">ea</a></li><li class="progresssection"><a href="4-nap.html">nap</a></li><li class="progresssection"><a href="4-gng.html">gng</a></li><li class="progresssection"><a href="4-rpoa.html">rpoa</a></li><li class="progresschapter"><a href="5-pp.html">5</a></li><li class="progresschapter"><a href="6-dlg.html">6</a></li><li class="progressnext"><a href="4-ea.html">&#10095;</a></li></ul></div>
</nav><!-- End of weave -->

		</main>
	</body>
</html>

